﻿Public Class Country

    Private _blockLevel As Integer = 0

    Property ShortName As CountryShortName
    
    Public Sub Load(stream As IO.StreamReader, country As CountryShortName)
        
        Dim shouldExit As Boolean = False
        Dim data As LineData

        Do Until shouldExit OrElse stream.EndOfStream
            data = ReadLineData(stream)

            Select Case data.LineType
                Case DataLineType.StarBlockChar
                    _blockLevel += 1
                Case DataLineType.EndBlockChar
                    _blockLevel -= 1
                    If _blockLevel = 0 Then
                        shouldExit = True
                    End If
                Case DataLineType.KeyValue
                    Select Case data.KeyValueData.Key

                        Case Else
                            AddUnmanagedLine(data.OriginalText)
                    End Select
            End Select
        Loop
    End Sub

    Public Shared Function IsCountry(text As String) As Boolean

        Contracts.Contract.Requires(Of ArgumentNullException)(text IsNot Nothing, "text should not be nothing")

        Dim result As Boolean

        result = [Enum].IsDefined(GetType(CountryShortName), text)

        Return result

    End Function

End Class
